package br.com.keropizza.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import br.com.keropizza.dominio.Sabor;

@Repository
public class SaborDao {

	@PersistenceContext
	private EntityManager entityManager;

	public void adiciona(Sabor sabor) {
		this.entityManager.persist(sabor);
	}

	public void altera(Sabor sabor) {
		this.entityManager.merge(sabor);
	}

	public void remove(Sabor sabor) {
		this.entityManager.remove(this.entityManager.getReference(Sabor.class,
				sabor.getId()));
	}

	public List<Sabor> buscaTodasSabor() {
		Query query = this.entityManager
				.createQuery("select s from sabor as s");
		return query.getResultList();
	}

	public Sabor buscaPorId(Long id) {
		return this.entityManager.find(Sabor.class, id);
	}
}
